package com.dmwork.vod.controller.front;

import com.aliyuncs.exceptions.ClientException;
import com.dmwork.common.base.result.ExceptionUtils;
import com.dmwork.common.base.result.R;
import com.dmwork.common.base.result.ResultCodeEnum;
import com.dmwork.service.base.exception.DmworkException;
import com.dmwork.vod.service.VodService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Api(description = "视频点播功能")
@RequestMapping("/front/dm_work/vod")
@RestController
public class VodController {

    @Autowired
    private VodService vodService;

    @ApiOperation("获取视频播放凭证")
    @GetMapping("get_play_auth/{videoSourceId}")
    public R getPlayAuth(@ApiParam(value = "视频资源id", required = true) @PathVariable("videoSourceId") String videoSourceId) {
        try {
            String playAuth = vodService.getPlayAuth(videoSourceId);
            return R.ok().message("获取成功").data("playAuth", playAuth);
        } catch (ClientException e) {
            log.info(ExceptionUtils.getMessage(e));
            throw new DmworkException(ResultCodeEnum.FETCH_PLAYAUTH_ERROR);
        }
    }

}
